package com.google.sydym6.logic.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class TableFactory {
	
	private static RadioDBHelper dbHelper;
	private static SQLiteDatabase db;
	
	public static void create(Context context) {
		if(TableFactory.db == null) {
			dbHelper = new RadioDBHelper(context); 
			db = dbHelper.openDataBase();
			Log.v("database", "db was opened");
		}
	}	
	
	public static void close() {
		if(dbHelper != null) {
			dbHelper.close();
			db = null;
			Log.v("database", "db was closed");
		}
	}	
	
	public static SQLiteDatabase getDataBase() {
		return db;
	}

	public static ITableWorker getTable(String name) {
		if (name.equals(DBConstants.RADIO_TABLE) || 
			name.equals(DBConstants.MUSIC_HISTORY_TABLE))
			return new TableWorker(name);
		else 
			return null;
	}
}
